<%layout("/common/_layout.html"){ %>
<script type="text/javascript">

function changeStatus(url,id,targetStatus) {
    
    $.ajax({
        url : url,
        data : {"id":id,"target_status":targetStatus},
        dataType : "json",
        async : true,
        success : function(data) {
          //parent.swal({title: "配置成功!", text: data.message, type: "success",timer: 2000,   showConfirmButton: false});
          parent.layer.msg("配置成功: " + data.message);
        }
        
    });
    
}
 
$(function(){
    var $mycheckbox = $('.switch-button').find("input[type='checkbox']");
    $mycheckbox.each(function(){
        var myid = $(this).attr("id");
        var prop = $(this).attr("prop");
        var url = "";
        if(prop.indexOf('enable')==0){
        	url = "${base}/memberOrg/changeStatus";
        }else{
        	url = "${base}/memberOrg/changeLock";
        }
        console.info(url);
        $(this).on({
            'switchChange.bootstrapSwitch': function(event, state) {
              console.log("switch:"+myid+":"+state);
    		  changeStatus(url,myid,state?1:0);
            }
        });
        
    });

  });
  
 
</script>
<%#ajax userTable:{%>
<div class="am-cf am-padding">
  <div class="am-fl am-cf"> <strong class="am-text-primary am-text-lg">系统管理</strong>
    /
    <small>人员管理</small>
  </div>
</div>

<div class="am-g">
  <div class="am-u-sm-12">
    <form class="am-form" id="list-form" action="${base}/memberOrg/list" method="post">
      <input type="hidden" id="keywords" name="keywords" value='${keywords!""}' />
      <table class="am-table am-table-bordered am-table-radius table-main" style="padding:0;">
        <tbody>
          <tr>
            <th class="am-text-middle">所属机构</th>
            <td>
              <div class="am-u-sm-10">
               <select data-am-selected="{btnSize:'sm',maxHeight: 400,btnWidth: '100%'}" name="org_id" id="org_id">
                            <%for(orgNode in orgList){%>
                            <option value="${orgNode.value}" <%if(org_id==orgNode.value){%>
                                selected
                                <%}%>>${orgNode.key}</option>
                            <%}%></select>
              </div>
            </td>

            <th class="am-text-middle">渠道类型</th>
            <td>
              <div class="am-u-sm-10">
              <select data-am-selected="{btnSize:'sm',maxHeight: 400,searchBox: 1}" name="class_id" id="class_id">
                            <option value="0" <%if(!has(class_id)){%>
                                checked
                                <%}%>>全部</option>
                            <%for(class in class_list){%>
                            <option value="${class.id}" <%if(class_id! == ""+class.id){%>
                                selected
                                <%}%>>${class.class_name}</option>
                            <%}%></select>
              </div>
            </td>
          </tr>
          
          <tr>
            <th class="am-text-middle">姓名</th>
            <td>
              <div class="am-u-sm-10">
                <input type="text" id="name" class="am-form-field am-input-sm" value="${name!}" />
              </div>
            </td>

            <th class="am-text-middle">工号</th>
            <td>
              <div class="am-u-sm-10">
                <input type="text" id="empcode" class="am-form-field am-input-sm" value="${empcode!}" />
              </div>
            </td>
          </tr>

          <tr>
            <th class="am-text-middle">手机号</th>
            <td>
              <div class="am-u-sm-10">
                <input type="text" id="username" class="am-form-field am-input-sm" value="${username!}" />
              </div>
            </td>

            <th class="am-text-middle">导入时间</th>
            <td>
              <div class="am-u-sm-10">
                <div class="am-form am-form-inline">
                  <div class="am-form-group am-form-icon"> <i class="am-icon-calendar"></i>
                    <input type="text" class="am-form-field am-input-sm" id="starttime" value="${starttime!}" placeholder="开始日期" data-am-datepicker></div>
                  <div class="am-form-group">至</div>
                  <div class="am-form-group am-form-icon"> <i class="am-icon-calendar"></i>
                    <input type="text" class="am-form-field am-input-sm" id="endtime" value="${endtime!}" placeholder="结束日期" data-am-datepicker></div>
                </div>
              </div>
            </td>
          </tr>
          <tr>
            <th class="am-text-middle">店铺名称</th>
            <td>
              <div class="am-u-sm-10">
                <input type="text" id="orgname" class="am-form-field am-input-sm" value="${orgname!}" />
              </div>
            </td>
            <th class="am-text-middle">人员状态</th>
            <td>
              <div class="am-u-sm-10">
                <select data-am-selected="{btnSize:'sm'}" id="enabled" name="enabled" >
                  <option value="-1" <%if(enabled! == "-1") {%>
                    selected
                    <%}%>>所有</option>
                  <option value="1" <%if(enabled! == "1") {%>
                    selected
                    <%}%>>启用</option>
                  <option value="0" <%if(enabled! == "0") {%>
                    selected
                    <%}%>>禁用</option>
                </select>
              </div>
            </td>
          </tr>
          <tr>
            <th class="am-text-middle">客户经理</th>
            <td>
              <div class="am-u-sm-10">
                <label class="am-radio-inline">
                    <input type="radio" id="beMgr" name="isMgr" value="1" data-am-ucheck <%if(isMgr! == "1"){%>
                                checked
                                <%}%> > 是
                  </label>
                  <label class="am-radio-inline">
                    <input type="radio" id="notMgr" name="isMgr" value="0" data-am-ucheck <%if(isMgr! == "0"){%>
                                checked
                                <%}%>> 否
                  </label>
                  <label class="am-radio-inline">
                    <input type="radio" id="whatever" name="isMgr" value="2" data-am-ucheck <%if(!has(isMgr)||(isMgr! == "2")){%>
                                checked
                                <%}%>> 全部
                  </label>
              </div>
            </td>
            <th class="am-text-middle">人员类型</th>
            <td>
              <div class="am-u-sm-10">
                <select data-am-selected="{btnSize:'sm'}" id="member_type" name="member_type" >
                  <option value="-1" <%if(member_type! == "-1") {%>
                    selected
                    <%}%>>所有</option>
                  <option value="1" <%if(member_type! == "1") {%>
                    selected
                    <%}%>>店长</option>
                  <option value="2" <%if(member_type! == "2") {%>
                    selected
                    <%}%>>店员</option>
                  <option value="3" <%if(member_type! == "3") {%>
                    selected
                    <%}%>>泛店员</option>
                </select>
              </div>
            </td>
          </tr>
          <tr>
            <td colspan="4">
              <div align='right'>
                <button type="button" class="am-btn am-btn-default am-btn-sm am-text-secondary" id="submit-btn">搜索</button>
              </div>
            </td>
          </tr>
        </tbody>
      </table>
    </form>
  </div>

  <div class="am-u-sm-12 am-u-md-12" style="padding:0 1.6rem 1.6rem 1rem;margin:0;">
    <div class="am-btn-toolbar" style="padding-left:.5rem;">
      <div class="am-btn-group am-btn-group-xs am-fl">
        <%if(so.hasPermission("MEMBER_ORG_IMPORT")) {%>
        <div class="am-btn-group am-btn-group-xs am-form-file">
          <button type="button" id="bt_import" class="am-btn am-btn-default">
            <span class="am-icon-archive"></span>
            导入人员
          </button>
          <input id="doc-form-file" type="file" name="import" onChange="ajaxUploadFile('doc-form-file','${base}/memberOrg/upload')" multiple></div>
        <%}%>
        <%if(so.hasPermission("MEMBERORG_UPLOAD_EMP")) {%>
        <div class="am-btn-group am-btn-group-xs am-form-file">
          <button type="button" id="bt_import_emp" class="am-btn am-btn-default">
            <span class="am-icon-archive"></span>
            补登工号
          </button>
          <input id="doc-form-file-emp" type="file" name="import_emp" onChange="ajaxUploadFile('doc-form-file-emp','${base}/memberOrg/upload4emp')" multiple></div>
        <%}%>
        <%if(so.hasPermission("MEMBER_ORG_EXPORT")) {%>
        <button type="button" id="bt_export" class="am-btn am-btn-default common-export" onClick="location.href='${base}/memberOrg/export'">
          <span class="am-icon-save"></span>
          导出
        </button>
        <%}%>

        <div class="am-dropdown" data-am-dropdown>
         <%if(so.hasPermission("MEMBER_EXPORT_TEMP")) {%>
          <button type="button" class="am-btn am-btn-default am-btn-xs am-dropdown-toggle"
                                                data-am-dropdown-toggle>
            <span class="am-icon-download"></span>
            模板
          </a>
        </button>
         <%}%>
        <ul class="am-dropdown-content">
          <li>
            <a href="${base}/memberOrg/template" >导入人员</a>
          </li>
          <li>
            <a href="${base}/memberOrg/template4emp">补登工号</a>
          </li>
        </ul>
      </div>
      <%if(so.hasPermission("MEMBER_ORG_DEL")) {%>
      <button type="button" id="deleteButton" disabled="disabled" class="am-btn am-btn-default"  onclick="deleteAll('${base}/memberOrg/delete')">
        <span class="am-icon-trash-o"></span>
        删除
      </button>
      <%}%>
      
      </div>
      <div class="am-text-xs am-fl am-margin-top-xs" style="color:red">&nbsp&nbsp*工号自动与BOSS系统同步，需手机号与boss工号一一对应才可正常使用大掌柜APP。默认密码为手机号后六位</div>
  </div>
</div>
</div>

<div class="am-g">
<div class="am-u-sm-12">

  <div class="am-scrollable-horizontal">
    <table class="am-table am-table-striped am-table-hover table-main">
      <thead>
        <tr class="am-text-nowrap">
          <th class="table-check">
            <input type="checkbox"  id="allCheck"/>
          </th>
          <th class="table-title">账号</th>
          <th class="table-title">姓名</th>
          <th class="table-title">工号</th>
          <th class="table-title">客户经理</th>
          <th class="table-title">所属店铺</th>
          <th class="table-title">渠道类型</th>
          <th class="table-title">身份</th>
          <th class="table-title">上级工号<br/>（泛店员有效）</th>
          <th class="table-title">审核时间<br/>（泛店员有效）</th>
          <th class="table-title">操作</th>
        </tr>
      </thead>
      <tbody>
        <%for(list in pager.list!){%>
        <tr>
          <td>
            <input type="checkbox" name="ids" value="${list.id}"></td>
          <td>${list.user_name}</td>
          <td>${list.name}</td>
          <td>${list.emp_code}</td>
          <td>${list.is_accounts_manager}</td>
          <td>
            <a href="${base!}/organization/preview?NumCode=${list.org_channel_code}">${list.DisplayName}</a>
          </td>
          <td>${list.class_name}</td>
          <td>
            <%if (list.member_type==1){%>
            店长
            <%}else if(list.member_type==2){%>
            店员
            <%}else if(list.member_type==3){%>
           泛店员
            <%}else{%>
           未知
            <%}%></td>
          <td>${list.parent_emp_code!''}</td>
          <td>${list.ratify_time,dateFormat="yyyy-MM-dd HH:mm:ss"}</td>
          <td class="switch-button" >
          
          <%if(list.member_type!=3){%>
          
            <input id="${list.id}" prop="enable" type="checkbox" data-size='xs' data-am-switch  data-off-text="已禁用" data-on-text="已启用"  
                  <%if (list.enabled==1){%> checked <%}%> /><br/>
                  
          <%}else{%>        
        	
        	<input id="${list.id}" prop="lock" type="checkbox" data-size='xs' data-am-switch  data-off-text="已解锁" data-on-text="已锁定"  
              <%if (list.is_lock==1){%> checked <%}%> />
          
          <%}%> 
            <!--<button type="button" class="am-btn am-btn-primary am-btn-xs" onclick="changeStatus('${base}/memberOrg/changeLock',${list.id},${(list.is_lock+1)%2})">
				<%if(list.is_lock==1){%>已解锁<%}else{%>已锁定<%}%>
			</button>-->
          </td>
        </tr>
        <%}%></tbody>
    </table>
  </div>

  <div class="am-cf">
    <!-- 分页 -->
    <%if (pager.list.~size >
    0){%>
    <div class="am-fr">
      <% include("/admin/common_pager.tpl"){}%></div>
    <%}else{%>
    <div class="am-kai">
      <h3>没有找到任何记录!</h3>
    </div>
    <%}%></div>

</div>
</div>

<div class="am-modal am-modal-no-btn" tabindex="-1" id="modal">
<div class="am-modal-dialog">
  <div class="am-modal-hd">
    <i class="am-icon-refresh am-icon-spin"></i>
    <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
  </div>
  <div class="am-modal-bd">正在处理，请稍等...</div>
</div>
</div>

<script type="text/javascript">
    $(function(){
      var keywordsObj = {};
      $("#submit-btn").on("click",function(){
        
        if($("#username").val())
          keywordsObj.username = $("#username").val();
          
        if($("#name").val())
          keywordsObj.name = $("#name").val();
          
        if($("#empcode").val())
          keywordsObj.empcode = $("#empcode").val();
          
        if($("#orgname").val())
          keywordsObj.orgname = $("#orgname").val();
          
        if($("#enabled").val())
          keywordsObj.enabled = $("#enabled").val();
          
        if($("#enabled").val())
          keywordsObj.enabled = $("#enabled").val();
          
        if($("#starttime").val())
          keywordsObj.starttime = $("#starttime").val();
         if($("#endtime").val())
          keywordsObj.endtime = $("#endtime").val();  
          
        var $checkObj = $("input[name='isMgr']");
            
        for(var i=0;i<$checkObj.length;i++){
            if($checkObj[i].checked){
                keywordsObj.isMgr =$checkObj[i].value;
                break;
            }
        } 
        
        if($("#class_id").val()){
            keywordsObj.class_id =$("#class_id").val();
        }
             
        if($("#org_id").val()){
              keywordsObj.org_id = $("#org_id").val();
        }
        
        if($("#member_type").val()){
        	keywordsObj.member_type = $("#member_type").val();
        }
              
        var keywords = "";
        if(!$.isEmptyObject(keywordsObj)){
          keywords = JSON.stringify(keywordsObj);
        }
        console.log("keywords = "+ keywords);

        $("#keywords").val(keywords);
        $("#list-form").submit();
      });
    });
 
  </script>
<%}%>
<%}%>
